package com.sishu.njrtsdms.jooq.generate.strategy;

import cn.hutool.core.util.StrUtil;
import org.jooq.codegen.DefaultGeneratorStrategy;
import org.jooq.meta.Definition;
import org.jooq.meta.TableDefinition;

public class CustomGeneratorStrategy extends DefaultGeneratorStrategy {

    /**
     * 表名前缀
     */
    public final static String TABLE_PREFIX = "tbl";


    /**
     * 指定Pojo类名生成规则
     */
    @Override
    public String getJavaClassName(Definition definition,
                                   Mode mode) {
        String result = super.getJavaClassName(definition, mode);
        // 定义类名前先去除表名固定前缀(如果有的话)
        result = StrUtil.replaceIgnoreCase(result, TABLE_PREFIX, StrUtil.EMPTY);
        switch (mode) {
//            case POJO -> result += "POJO";
            case DAO -> result = StrUtil.replaceIgnoreCase(result, "dao", StrUtil.EMPTY) + "DAO";
            case DEFAULT -> {
                if (definition instanceof TableDefinition) {
                    result = "T" + result;
                }
            }
            default -> {
            }
        }
        return result;
    }


}
